home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 319.adf / CNewsSrc / cnews.src.lzh / libcnews / config.c < prev    next >
C/C++ Source or Header  |  1989-07-03  |  5KB  |  258 lines

  1. /*
  2.  * news configuration inquiry
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include "libc.h"
  8. #include "news.h"
  9. #include "config.h"
  10.  
  11. #ifndef NULL
  12. #  define    NULL    0
  13. #endif
  14.  
  15. #ifndef NEWSCTL
  16. /* =()<#define    NEWSCTL    "@<NEWSCTL>@">()= */
  17. /* #define    NEWSCTL        "News:usr/lib/news" */
  18. #define    NEWSCTL        "News:news"
  19. #endif
  20.  
  21. #ifndef NEWSPATH
  22. /* =()<#define    NEWSPATH    "@<NEWSPATH>@">()= */
  23. #define    NEWSPATH    "/bin:/usr/bin"
  24. #endif
  25.  
  26. #ifndef NEWSARTS
  27. /* =()<#define    NEWSARTS    "@<NEWSARTS>@">()= */
  28. /* #define    NEWSARTS    "/usr/spool/news" */
  29. #define    NEWSARTS    "News:"
  30. #endif
  31.  
  32. #ifndef NEWSBIN
  33. /* =()<#define    NEWSBIN    "@<NEWSBIN>@">()= */
  34. /* #define    NEWSBIN        "/usr/lib/newsbin" */
  35. #define    NEWSBIN        "News:newsbin"
  36. #endif
  37.  
  38. #ifndef NEWSUMASK
  39. /* =()<#define    NEWSUMASK    @<NEWSUMASK>@>()= */
  40. #define    NEWSUMASK    002
  41. #endif
  42.  
  43. #ifndef NEWSMASTER
  44. /* =()<#define    NEWSMASTER    "@<NEWSMASTER>@">()= */
  45. #define    NEWSMASTER    "usenet"
  46. #endif
  47.  
  48. static char *pwd = NULL;    /* Current directory, NULL means unknown. */
  49. static int dirsset = NO;    /* Have the following been set up? */
  50. static char *arts = NEWSARTS;
  51. static char *bin = NEWSBIN;
  52. static char *ctl = NEWSCTL;
  53. static char *path = NEWSPATH;
  54. static int numask = NEWSUMASK;
  55. static char *nmaster = NEWSMASTER;
  56. #define    DIRS()    if (!dirsset) setdirs()
  57.  
  58. extern char *strcpy();
  59. extern char *strcat();
  60. extern char *getenv();
  61.  
  62. /*
  63.  * setdirs - set up stuff from environment, for use by other functions
  64.  *
  65.  * Invokes user-supplied function unprivileged() if non-standard values used.
  66.  */
  67. static void setdirs()
  68. {
  69.     register char *p;
  70.     register int nonstd = NO;
  71.     register int mask;
  72.     register char *scan;
  73.  
  74.     if (dirsset)
  75.         return;
  76.  
  77.     p = getenv("NEWSARTS");
  78.     if (p != NULL && !STREQ(p, arts)) {
  79.         nonstd = YES;
  80.         arts = p;
  81.     }
  82.     p = getenv("NEWSCTL");
  83.     if (p != NULL && !STREQ(p, ctl)) {
  84.         ctl = p;
  85.         nonstd = YES;
  86.     }
  87.     p = getenv("NEWSPATH");
  88.     if (p != NULL && !STREQ(p, path)) {
  89.         path = p;
  90.         nonstd = YES;
  91.     }
  92.     p = getenv("NEWSBIN");
  93.     if (p != NULL && !STREQ(p, bin)) {
  94.         bin = p;
  95.         nonstd = YES;
  96.     }
  97.     p = getenv("NEWSUMASK");
  98.     if (p != NULL) {
  99.         mask = 0;
  100.         for (scan = p; *scan != '\0'; scan++)
  101.             if ('0' <= *scan && *scan <= '7' && mask <= 077)
  102.                 mask = (mask << 3) | (*scan - '0');
  103.             else {    /* Garbage, ignore it. */
  104.                 mask = numask;
  105.                 break;            /* NOTE BREAK OUT */
  106.             }
  107.         if (mask != numask) {
  108.             numask = mask;
  109.             nonstd = YES;
  110.         }
  111.     }
  112.     p = getenv("NEWSMASTER");
  113.     if (p != NULL && !STREQ(p, nmaster)) {
  114.         nmaster = p;
  115.         nonstd = YES;
  116.     }
  117.     dirsset = YES;
  118.     if (nonstd)
  119.         unprivileged();
  120. }
  121.  
  122. /*
  123.  * artfile - best pathname for a file in NEWSARTS
  124.  */
  125. char *artfile(base)
  126. char *base;
  127. {
  128.     static char *artf = NULL;
  129.  
  130.     DIRS();
  131.  
  132.     if (base == NULL)    /* he just wants the directory */
  133.         return (arts);
  134.  
  135.     if (artf != NULL)
  136.         free(artf);        /* toss old returned value */
  137.     if (pwd != NULL && STREQ(pwd, arts))
  138.         artf = strsave(base);
  139. #ifdef AMIGA
  140.     else if (arts[ strlen(arts)-1 ] == ':')
  141.         artf = str3save(arts, "", base);
  142. #endif
  143.     else
  144.         artf = str3save(arts, SFNDELIM, base);
  145.  
  146.     return (artf);
  147. }
  148.  
  149. /*
  150.  * fullartfile - full pathname for a file in NEWSARTS
  151.  */
  152. char *fullartfile(base)
  153. char *base;
  154. {
  155.     register char *p;
  156.     register char *pwdsave;
  157.  
  158.     pwdsave = pwd;
  159.     pwd = NULL;        /* fool artfile() into giving full path */
  160.     p = artfile(base);
  161.     pwd = pwdsave;
  162.     return (p);
  163. }
  164.  
  165. /*
  166.  * ctlfile - full pathname for a file in NEWSCTL
  167.  */
  168. char *ctlfile(base)
  169. char *base;
  170. {
  171.     static char *ctlf = NULL;
  172.  
  173.     DIRS();
  174.  
  175.     if (ctlf != NULL)
  176.         free(ctlf);        /* toss old returned value */
  177.  
  178.     if (base == NULL) {
  179.         ctlf = NULL;
  180.         return(ctl);
  181.     } else {
  182. #ifdef AMIGA
  183.         if (ctl[ strlen(ctl)-1 ] == ':')
  184.             ctlf = str3save(ctl, "", base);
  185.         else
  186. #endif
  187.             ctlf = str3save(ctl, SFNDELIM, base);
  188.         return(ctlf);
  189.     }
  190. }
  191.  
  192. /*
  193.  * binfile - full pathname for a file in NEWSBIN
  194.  */
  195. char *binfile(base)
  196. char *base;
  197. {
  198.     static char *binf = NULL;
  199.  
  200.     DIRS();
  201.  
  202.     if (binf != NULL)
  203.         free(binf);        /* toss old returned value */
  204.  
  205.     if (base == NULL) {
  206.         binf = NULL;
  207.         return(bin);
  208.     } else {
  209. #ifdef AMIGA
  210.         if (bin[ strlen(bin)-1 ] == ':')
  211.             binf = str3save(bin, "", base);
  212.         else
  213. #endif
  214.         binf = str3save(bin, SFNDELIM, base);
  215.         return (binf);
  216.     }
  217. }
  218.  
  219. /*
  220.  * cd - change to a directory, with checking
  221.  */
  222. void cd(dir)
  223. char *dir;
  224. {
  225.     if (pwd != NULL)
  226.         free(pwd);
  227.     if (chdir(dir) < 0)
  228.         errunlock("cannot chdir(%s)", dir);
  229.     pwd = strsave(dir);
  230. }
  231.  
  232. /*
  233.  * newspath - search path for normal system commands
  234.  */
  235. char *newspath()
  236. {
  237.     DIRS();
  238.     return(path);
  239. }
  240.  
  241. /*
  242.  * newsumask - suitable value of umask for news stuff
  243.  */
  244. int newsumask()
  245. {
  246.     DIRS();
  247.     return(numask);
  248. }
  249.  
  250. /*
  251.  * newsmaster - mail address to complain to
  252.  */
  253. char *newsmaster()
  254. {
  255.     DIRS();
  256.     return(nmaster);
  257. }
  258.